package com.weita.lightfood.service;


import cn.binarywang.wx.miniapp.bean.WxMaTemplateData;
import com.weita.lightfood.model.dao.*;
import com.weita.lightfood.model.entity.Address;
import com.weita.lightfood.model.entity.Dish;
import com.weita.lightfood.model.entity.Order;
import com.weita.lightfood.model.query.order.GenerateOrderQuery;
import com.weita.lightfood.model.query.order.RefundOrderQuery;
import com.weita.lightfood.model.vo.dish.DishCustomizedDishVo;
import com.weita.lightfood.model.vo.dish.DishDetailsVo;
import com.weita.lightfood.model.vo.material.MaterialAttributeVo;
import com.weita.lightfood.model.vo.order.*;
import com.weita.lightfood.model.vo.user.UserCustomizedDishVo;
import com.weita.lightfood.utils.DateUtil;
import com.weita.lightfood.utils.PushUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author IT_Monster at 2019/03/27 23:25.
 */
@Service
public class OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private AddressDao addressDao;
    @Autowired
    private DishDao dishDao;
    @Autowired
    private MaterialDao materialDao;
    @Autowired
    private HealthReportDao healthReportDao;
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserService userService;
    /**
     * 商家id
     */
    private final int MERCHANT_ID = 44;


    /**
     * 根据日期判断是不是今天
     * @param date
     * @return
     */
    private boolean isTodayOrder(String date){
        //获取当前年月日
        String nowTime = DateUtil.nowDate();
        int result = nowTime.compareTo(date);
        if (result != 0){
            //不是今天的单
            return false;
        }else {
            //今日单
            return true;
        }
    }

    /**
     * 早餐下单
     */
    public String generateBreakfastOrder(GenerateOrderQuery generateOrderQuery, String endTime) throws Exception {
        String orderTime = generateOrderQuery.getOrderTime();
        if (this.isTodayOrder(orderTime)) {
            //如果是今日订单，需要进行下单截止判断
            if (DateUtil.isEnd(endTime)) {
                return "今日早餐下单时间已过，您可预定明日早餐";
            } else {
                orderTime += " " + DateUtil.nowTime();
                generateOrderQuery.setOrderTime(orderTime);
                return this.generateOrder(generateOrderQuery);
            }
        } else {
            orderTime += " " + DateUtil.nowTime();
            generateOrderQuery.setOrderTime(orderTime);
            this.generateOrder(generateOrderQuery);
            return "预定早餐成功";
        }
    }

    /**
     * 午餐下单
     */
    public String generateLunchOrder(GenerateOrderQuery generateOrderQuery, String endTime) throws Exception {
        String orderTime = generateOrderQuery.getOrderTime();
        if (this.isTodayOrder(orderTime)) {
            //如果是今日订单，需要进行下单截止判断
            if (DateUtil.isEnd(endTime)) {
                return "今日午餐下单时间已过，您可预定明日午餐";
            } else {
                orderTime += " " + DateUtil.nowTime();
                generateOrderQuery.setOrderTime(orderTime);
                return this.generateOrder(generateOrderQuery);
            }
        } else {
            orderTime += " " + DateUtil.nowTime();
            generateOrderQuery.setOrderTime(orderTime);
            this.generateOrder(generateOrderQuery);
            return "预定午餐成功";
        }
    }

    /**
     * 晚餐下单
     */
    public String generateDinnerOrder(GenerateOrderQuery generateOrderQuery, String endTime) throws Exception {
        String orderTime = generateOrderQuery.getOrderTime();
        if (this.isTodayOrder(orderTime)) {
            //如果是今日订单，需要进行下单截止判断
            if (DateUtil.isEnd(endTime)) {
                return "今日晚餐下单时间已过，您可预定明日晚餐";
            } else {
                orderTime += " " + DateUtil.nowTime();
                generateOrderQuery.setOrderTime(orderTime);
                return this.generateOrder(generateOrderQuery);
            }
        } else {
            orderTime += " " + DateUtil.nowTime();
            generateOrderQuery.setOrderTime(orderTime);
            this.generateOrder(generateOrderQuery);
            return "预定晚餐成功";
        }
    }

    /**
     * 生成订单（在商家和用户之间进行消息推送）
     */
    private String generateOrder(GenerateOrderQuery generateOrderQuery) throws Exception {
        //向数据库插入订单数据
        orderDao.generateOrder(generateOrderQuery);
        String formId = userService.getFormId(MERCHANT_ID);
        String openId = userService.getOpenId(MERCHANT_ID);
        List<WxMaTemplateData> templateData = new ArrayList<>();
        WxMaTemplateData data1 = new WxMaTemplateData("keyword1","来新订单了，请及时处理");
        WxMaTemplateData data2 = new WxMaTemplateData("keyword2",generateOrderQuery.getOrderTime());
        templateData.add(data1);
        templateData.add(data2);
        PushUtil.wechatPushToUser(openId, formId, templateData);
        return "下单成功";
    }


    /**
     * /用户获取待评价订单
     */
    public List<OrderVo> getDPJOrder(int userID) throws Exception {
        return orderDao.getDPJOrder(userID);
    }

    /**
     * 用户获取申请退款订单
     */
    public List<OrderVo> getSQTKOrder(int userID) throws Exception {
        return orderDao.getSQTKOrder(userID);
    }

    /**
     * 用户获取退款订单
     */
    public List<OrderVo> getTKOrder(int userID) throws Exception {
        return orderDao.getTKOrder(userID);
    }

    /**
     * 用户获取所有订单
     */
    public List<OrderVo> getAll(int userID) throws Exception {
        return orderDao.getAll(userID);
    }

    /**
     * 商家获取所有已接单订单0
     */
    public List<Order> getReceivingOrder() throws Exception {
        return orderDao.getReceivingOrder();
    }

    /**
     * 商家获取退款申请订单8
     */
    public List<RefundOrderVo> getAllTKSQOrder() throws Exception {
        return orderDao.getAllTKSQOrder();
    }

    /**
     * 商家获取已完成订单467
     */
    public List<Order> getAllCGOrder() throws Exception {
        return orderDao.getAllCGOrder();
    }

    /**
     * 用户确认收货---> 已送达
     */
    public String confirmReceipt(int orderId) throws Exception {
        orderDao.changeOrderState(2, orderId);
        return "确认收货成功";
    }

    /**
     * 设置订单详情页面头部信息
     *
     * @param linkman
     * @param phoneNum
     * @param address
     * @param dishName
     * @param dishNum
     * @param tableNum
     * @return
     */
    private OrderDetailsVo setOrderHead(String linkman, String phoneNum, String address, String dishName, int dishNum, int tableNum) {
        OrderDetailsVo orderDetailsVo = new OrderDetailsVo();
        //设置收货人姓名
        orderDetailsVo.setUserName(linkman);
        //设置收货人联系方式
        orderDetailsVo.setPhoneNumber(phoneNum);
        //设置收货地址
        orderDetailsVo.setAddress(address);
        //设置菜谱名
        orderDetailsVo.setDishName(dishName);
        //设置菜品数量
        orderDetailsVo.setDishNumber(dishNum);
        //设置餐具数量
        orderDetailsVo.setTableNumber(tableNum);
        return orderDetailsVo;
    }

    /**
     * 设置退款订单详情页面头部信息
     *
     * @param linkman
     * @param phoneNum
     * @param address
     * @param dishName
     * @param dishNum
     * @param tableNum
     * @return
     */
    private RefundOrderDetailsVo setRefundOrderHead(String linkman, String phoneNum, String address, String dishName, int dishNum, int tableNum) {
        RefundOrderDetailsVo orderDetailsVo = new RefundOrderDetailsVo();
        //设置收货人姓名
        orderDetailsVo.setUserName(linkman);
        //设置收货人联系方式
        orderDetailsVo.setPhoneNumber(phoneNum);
        //设置收货地址
        orderDetailsVo.setAddress(address);
        //设置菜谱名
        orderDetailsVo.setDishName(dishName);
        //设置菜品数量
        orderDetailsVo.setDishNumber(dishNum);
        //设置餐具数量
        orderDetailsVo.setTableNumber(tableNum);
        return orderDetailsVo;
    }

    /**
     * 将食材名拼成字符串
     *
     * @param meat
     * @return
     */
    private String getMaterialNameString(List<MaterialAttributeVo> meat) {
        if (meat.size() < 1) {
            return "";
        }
        String material = "";
        for (int index = 0; index < meat.size() - 1; index++) {
            material += meat.get(index).getMaterialName() + ",";
        }
        material += meat.get(meat.size() - 1).getMaterialName();
        return material;
    }

    /**
     * 将食材重量拼成字符串
     */
    private String getMaterialWeightString(List<MaterialAttributeVo> meat) {
        if (meat.size() < 1) {
            return "";
        }
        String weight = "";
        for (int index = 0; index < meat.size() - 1; index++) {
            weight += meat.get(index).getMaterialWeight() + ",";
        }
        weight += meat.get(meat.size() - 1).getMaterialWeight();
        return weight;
    }

    /**
     * 通过用户id和食谱id定制饮食
     *
     * @param dishId
     * @param userId
     * @return List<MaterialAttributeVo>
     */
    private List<MaterialAttributeVo> customizedDish(int dishId, int userId) throws Exception {
        //维持目标0
        final int keepAim = 0;
        //增肌目标1
        final int gainMuscleAim = 1;
        //减肥目标2
        final int loseWeightAim = 2;
        //获取菜品所有食材
        List<MaterialAttributeVo> material = materialDao.getMaterial(dishId);
        //获取用户预算热量     用户健康表
        double calorieBudget = healthReportDao.getCalorieBudget(userId);
        //获取用户目标（维持增肌减肥）、初始体重、目标体重、减肥天数
        UserCustomizedDishVo userCustomizedDishVo = userDao.getCustomizedDishData(userId);
        //获取菜品热量、早中晚状态
        DishCustomizedDishVo dishCustomizedDishVo = dishDao.getDishCustomizedDishVo(dishId);
        //热量占预算热量比重（根据早中晚餐计算）
        double dishRate;
        //菜品所属早中晚状态
        int state = dishCustomizedDishVo.getState();
        if (state == 0) {
            dishRate = 0.341;
        } else if (state == 1) {
            dishRate = 0.347;
        } else {
            dishRate = 0.312;
        }
        //维持状态下用户食材配重比例
        double keepRate = (dishRate * calorieBudget) / dishCustomizedDishVo.getCalorie();
        //获取用户饮食目标（维持0增肌1减肥2）
        int aim = userCustomizedDishVo.getAim();
        if (aim == keepAim || aim == gainMuscleAim) {
            //得到维持状态下用户食材重量
            for (MaterialAttributeVo m : material) {
                m.setMaterialWeight((int) (m.getMaterialWeight() * keepRate));
            }
            if (aim == keepAim) {
                return material;
            } else {
                //将所有增肌标签(0)的食材重量加倍再返回
                material = doubleMaterial(material, 0, 2);
                return material;
            }
        } else if (aim == loseWeightAim) {
            //目标体重和初始体重的差值
            double weightChange = userCustomizedDishVo.getFirstWeight() - userCustomizedDishVo.getAimWeight();
            //得到减肥状态下用户食材重量
            //计算用户减肥时每天应少摄入的热量
            double reduceQDayly = (weightChange / userCustomizedDishVo.getWeightTime()) * 7700;
            //减肥状态下用户食材配重比例
            double loseWeightRate = (calorieBudget - (reduceQDayly)) * dishRate / dishCustomizedDishVo.getCalorie();
            for (MaterialAttributeVo m : material) {
                m.setMaterialWeight((int) (m.getMaterialWeight() * loseWeightRate));
            }
            double doubleRate = (weightChange / userCustomizedDishVo.getFirstWeight()) * 2 + 1;

            //将所有减肥标签(1)的食材加倍
            material = doubleMaterial(material, 1, doubleRate);
            return material;
        }
        return material;
    }

    /**
     * 加倍指定类型的食材 0代表增肌，1代表减肥，2代表其它
     *
     * @param material
     * @param tag
     * @return
     */
    private List<MaterialAttributeVo> doubleMaterial(List<MaterialAttributeVo> material, int tag, double doubleRate) {
        //加重食材产生的额外的热量
        double additionalCalorie = 0.0;
        //除佐料食材外非加重类型的食材
        int count = 0;
        for (MaterialAttributeVo m : material) {
            //0代表增肌，1代表减肥，2代表其它
            if (m.getTag() == tag) {
                //加倍产生的额外热量   m.getCalorie() 得到的是每100g食材的热量
                additionalCalorie += m.getCalorie() * m.getMaterialWeight() * (doubleRate - 1) / 100;
                //当前遍历的食材属于指定食材，重量加倍
                m.setMaterialWeight((int)(m.getMaterialWeight() * doubleRate));
            } else if (m.getType() != 2) {
                //0代表肉类谷物坚果，1代表蔬菜水果，2代表佐料
                //记录不属于指定加倍类型食材，且不是佐料类食材的数量（佐料类食材不计入热量）
                count++;
            }
        }
        //其它非佐料类食材平摊的热量
        double aveCalorie = additionalCalorie / count;
        //将其它非佐料类食材减去对应平摊热量的重量
        for (MaterialAttributeVo m : material) {
            //抓取非指定加倍的非佐料类食材
            if (m.getType() != 2 && m.getTag() != tag) {
                m.setMaterialWeight(m.getMaterialWeight() - (int) (100 * aveCalorie / m.getCalorie()));
            }
        }
        return material;
    }

    /**
     * 获取用户端查看订单详情数据
     * @param orderId
     * @return
     */
    public UserOrderDetailsVo userOrderDetails(int orderId) throws Exception {
        UserOrderDetailsVo userOrderDetailsVo = new UserOrderDetailsVo();
        //通过订单id获取订单
        Order order = orderDao.getOrderById(orderId);
        //通过orderId获取地址id（order）
        int addressId = orderDao.getAddressIdByOrderId(orderId);
        //通过地址id获取地址信息（address）
        Address address = addressDao.getAddressById(addressId);
        //通过orderId获取菜品id（dish）
        int dishId = orderDao.getDishIdByOrderId(orderId);
        //通过菜品id获取菜品名
        Dish dish = dishDao.getDishById(dishId);

        //设置用户端查看订单详情数据
        userOrderDetailsVo.setDishName(dish.getName());
        userOrderDetailsVo.setPrice(dish.getPrice());
        userOrderDetailsVo.setTotalPrice(order.getGrossPrice());
        userOrderDetailsVo.setDishNumber(order.getDishNumber());
        userOrderDetailsVo.setTableNumber(order.getTableNumber());
        userOrderDetailsVo.setUserName(address.getLinkman());
        userOrderDetailsVo.setAddress(address.getAddress());
        userOrderDetailsVo.setPhoneNumber(address.getPhoneNum());
        userOrderDetailsVo.setDishState(dish.getState());
        return userOrderDetailsVo;
    }


    /**
     * 获取菜品详情
     * @param userId
     * @param dishId
     * @return
     */
    public DishDetailsVo getDishDetails(int userId, int dishId) throws Exception {
        DishDetailsVo dishDetailsVo = new DishDetailsVo();
        //获取定制的食材配重(食材名和配重放在两个不同的逗号隔开的字符串中，按在字符串中的位置关联)
        List<MaterialAttributeVo> material = this.customizedDish(dishId, userId);
        //肉类谷物坚果
        List<MaterialAttributeVo> meat = new ArrayList<>();
        //蔬菜水果
        List<MaterialAttributeVo> vegetable = new ArrayList<>();
        //佐料
        List<MaterialAttributeVo> seasoning = new ArrayList<>();
        //食材类别（0代表肉类谷物坚果，1代表蔬菜水果，2代表佐料）
        for (MaterialAttributeVo mv : material) {
            switch (mv.getType()) {
                case 0: {
                    meat.add(mv);
                    break;
                }
                case 1: {
                    vegetable.add(mv);
                    break;
                }
                case 2: {
                    seasoning.add(mv);
                    break;
                }
                default:
                    break;
            }
        }
        /**
         * 将食材信息拼成字符串
         */
        //肉类食材
        String meatMaterial = this.getMaterialNameString(meat);
        //肉类食材重量
        String meatMaterialWeight = this.getMaterialWeightString(meat);
        //蔬菜类食材
        String vegetableMaterial = this.getMaterialNameString(vegetable);
        //蔬菜类食材重量
        String vegetableMaterialWeight = this.getMaterialWeightString(vegetable);
        //佐料类食材
        String seasoningMaterial = this.getMaterialNameString(seasoning);
        //佐料类食材重量
        String seasoningMaterialWeight = this.getMaterialWeightString(seasoning);
        //设置肉类食材
        dishDetailsVo.setMeatMaterial(meatMaterial);
        //设置肉类食材重量
        dishDetailsVo.setMeatMaterialWeight(meatMaterialWeight);
        //设置蔬菜类食材
        dishDetailsVo.setVegetableMaterial(vegetableMaterial);
        //设置蔬菜类食材重量
        dishDetailsVo.setVegetableMaterialWeight(vegetableMaterialWeight);
        //设置佐料类食材
        dishDetailsVo.setSeasoningMaterial(seasoningMaterial);
        //设置佐料类食材重量
        dishDetailsVo.setSeasoningMaterialWeight(seasoningMaterialWeight);

        return dishDetailsVo;
    }

    /**
     * 获取订单详情
     *
     * @param orderId
     * @return
     */
    public OrderDetailsVo orderDetails(int orderId) throws Exception {
        OrderDetailsVo orderDetailsVo;
        //通过订单id获取订单
        Order order = orderDao.getOrderById(orderId);
        //通过orderId获取地址id（order）
        int addressId = orderDao.getAddressIdByOrderId(orderId);
        //通过地址id获取地址信息（address）
        Address address = addressDao.getAddressById(addressId);
        //通过orderId获取菜品id（dish）
        int dishId = orderDao.getDishIdByOrderId(orderId);
        //通过菜品id获取菜品名
        String dishName = dishDao.getDishNameById(dishId);
        int userId = orderDao.getUserIdByOrderId(orderId);
        //获取定制的食材配重(食材名和配重放在两个不同的逗号隔开的字符串中，按在字符串中的位置关联)
        List<MaterialAttributeVo> material = this.customizedDish(dishId, userId);
        //肉类谷物坚果
        List<MaterialAttributeVo> meat = new ArrayList<>();
        //蔬菜水果
        List<MaterialAttributeVo> vegetable = new ArrayList<>();
        //佐料
        List<MaterialAttributeVo> seasoning = new ArrayList<>();
        //食材类别（0代表肉类谷物坚果，1代表蔬菜水果，2代表佐料）
        for (MaterialAttributeVo mv : material) {
            switch (mv.getType()) {
                case 0: {
                    meat.add(mv);
                    break;
                }
                case 1: {
                    vegetable.add(mv);
                    break;
                }
                case 2: {
                    seasoning.add(mv);
                    break;
                }
                default:
                    break;
            }
        }
        /**
         * 将食材信息拼成字符串
         */
        //肉类食材
        String meatMaterial = this.getMaterialNameString(meat);
        //肉类食材重量
        String meatMaterialWeight = this.getMaterialWeightString(meat);
        //蔬菜类食材
        String vegetableMaterial = this.getMaterialNameString(vegetable);
        //蔬菜类食材重量
        String vegetableMaterialWeight = this.getMaterialWeightString(vegetable);
        //佐料类食材
        String seasoningMaterial = this.getMaterialNameString(seasoning);
        //佐料类食材重量
        String seasoningMaterialWeight = this.getMaterialWeightString(seasoning);
        orderDetailsVo = this.setOrderHead(address.getLinkman(), address.getPhoneNum(), address.getAddress(), dishName, order.getDishNumber(), order.getTableNumber());
        //设置肉类食材
        orderDetailsVo.setMeatMaterial(meatMaterial);
        //设置肉类食材重量
        orderDetailsVo.setMeatMaterialWeight(meatMaterialWeight);
        //设置蔬菜类食材
        orderDetailsVo.setVegetableMaterial(vegetableMaterial);
        //设置蔬菜类食材重量
        orderDetailsVo.setVegetableMaterialWeight(vegetableMaterialWeight);
        //设置佐料类食材
        orderDetailsVo.setSeasoningMaterial(seasoningMaterial);
        //设置佐料类食材重量
        orderDetailsVo.setSeasoningMaterialWeight(seasoningMaterialWeight);
        return orderDetailsVo;
    }


    /**
     * 获取退款订单详情
     */
    public RefundOrderDetailsVo refundOrderDetails(int orderId) throws Exception {
        RefundOrderDetailsVo refundOrderDetailsVo;
        //通过订单id获取订单
        Order order = orderDao.getOrderById(orderId);
        //通过orderId获取地址id（order）
        int addressId = orderDao.getAddressIdByOrderId(orderId);
        //通过地址id获取地址信息（address）
        Address address = addressDao.getAddressById(addressId);
        //通过orderId获取菜品id（dish）
        int dishId = orderDao.getDishIdByOrderId(orderId);
        //通过菜品id获取菜品名
        String dishName = dishDao.getDishNameById(dishId);
        //获取订单退款理由
        String reason = orderDao.getReasonByOrderId(orderId);
        refundOrderDetailsVo = this.setRefundOrderHead(address.getLinkman(), address.getPhoneNum(), address.getAddress(), dishName, order.getDishNumber(), order.getTableNumber());
        refundOrderDetailsVo.setReason(reason);
        return refundOrderDetailsVo;
    }


    /***********>userAlias<*********需要推送消息***********>msg<*********************/
    /**
     * 用户申请取消订单(先将订单状态设置为8标识申请退款，并将订单添加到退款订单表中，再推送消息给商家来决定是否退款)
     */
    public String applicationForDrawback(RefundOrderQuery refundOrderQuery) throws Exception {
        orderDao.applicationForDrawback(refundOrderQuery);
        orderDao.changeOrderState(3, refundOrderQuery.getOrderId());
        //获取商家设备id
        return "取消订单申请提交成功";
    }

    /**
     * 商家拒绝取消订单
     */
    public String refuseDrawback(int orderId) throws Exception {

        //将订单状态改为5退款失败
        orderDao.changeOrderState(5, orderId);
        return "拒绝取消订单";
    }


    /**
     * 商家同意取消订单
     *
     * @param orderId
     * @return
     */
    public String agreeDrawback(int orderId) throws Exception {
        //将订单状态改为4退款成功
        orderDao.changeOrderState(4, orderId);
        return "同意取消订单";
    }

    /**
     * 获取本月订单
     */
    private List<Order> getThisMonthOrders() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        String thisMonth = sdf.format(new Date());
        return orderDao.getMonthOrders(thisMonth);
    }

    /**
     * 获取本月订单交易数据
     */
    public ThisMonthTotalData getThisMonthTotalData() throws Exception {
        ThisMonthTotalData thisMonthTotalData = new ThisMonthTotalData();
        List<Order> thisMonthOrders = this.getThisMonthOrders();
        int refundNum = 0;
        double grossAmount = 0;
        for (Order o : thisMonthOrders) {
            grossAmount += o.getGrossPrice();
            if (o.getState() == 6) {
                refundNum++;
            }
        }
        thisMonthTotalData.setGrossAmount(grossAmount);
        thisMonthTotalData.setRefundOrdersNum(refundNum);
        thisMonthTotalData.setOrdersNum(thisMonthOrders.size());
        return thisMonthTotalData;
    }

    /**
     * 商家配送订单
     */
    public String distributionOrder(int orderId) throws Exception {
        orderDao.changeOrderState(1, orderId);
        return "订单开始配送";
    }


    /**
     * 当月订单总览
     */
    public Map myOrders() throws Exception {
        Map<String, Object> result = new HashMap(5);
        List<Order> thisMonthOrders = this.getThisMonthOrders();
        List<MerchantOrder> list = new ArrayList<>();
        //入账
        int total = 0;
        //退款
        int refundTotal = 0;
        for (Order o : thisMonthOrders) {
            MerchantOrder merchantOrder = new MerchantOrder();
            if (o.getState() == 6) {
                merchantOrder.setGrossPrice((0 - o.getGrossPrice()) + "");
                refundTotal += o.getGrossPrice();
            } else {
                merchantOrder.setGrossPrice("+" + o.getGrossPrice());
                total += o.getGrossPrice();
            }
            merchantOrder.setOrderId(o.getId() + "");
            merchantOrder.setOrderTime(o.getOrderTime());
            list.add(merchantOrder);
        }

        result.put("order", list);
        result.put("total", total);
        result.put("refundTotal", refundTotal);
        return result;
    }

    /**
     * 当月退款订单总览
     */
    public List<MerchantOrder> myRefundOrders() throws Exception {
        List<Order> thisMonthOrders = this.getThisMonthOrders();
        List<MerchantOrder> list = new ArrayList<>();
        for (Order o : thisMonthOrders) {
            if (o.getState() == 6) {
                MerchantOrder merchantOrder = new MerchantOrder();
                merchantOrder.setGrossPrice((0 - o.getGrossPrice()) + "");
                merchantOrder.setOrderId(o.getId() + "");
                merchantOrder.setOrderTime(o.getOrderTime());
                list.add(merchantOrder);
            }
        }
        return list;
    }

}
